#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int Mv(const char *p, const char *q)
{

	int src = open(p,O_RDONLY);
	int dst = open(q,O_WRONLY|O_CREAT|O_TRUNC,0666);
	if(-1 == src || -1 == dst)
	{
		perror("open");
		return 1;
	}
	while(1)
	{
		char buf[512] = {0};
		int ret = read(src,buf,sizeof(buf));
		if(ret <= 0)
		{
			break;
		}
		write(dst,buf,ret);
	}
	close(src);
	close(dst);
	int ret = rename(p,q);
	if(-1 == ret)
	{
		perror("rename");
		return 1;
	}
	rmdir(p);
	return 0;
}

